/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.dao.impl;

import com.legendshop.dao.impl.GenericDaoImpl;
import com.legendshop.dao.support.*;
import com.legendshop.dao.support.lambda.LambdaEntityCriterion;
import com.legendshop.oa.constants.Constants;
import com.legendshop.oa.dao.ProjectPlanDao;
import com.legendshop.oa.dto.ProjectPlanQueryDto;
import com.legendshop.oa.model.ProjectPlan;
import com.legendshop.dao.sql.ConfigCode;

import java.util.List;

/**
 * The Class ProjectPlanDaoImpl. Dao实现类
 */

public class ProjectPlanDaoImpl extends GenericDaoImpl<ProjectPlan, Long> implements ProjectPlanDao {

	/**
	 * 根据商城获取列表
	 */
	public List<ProjectPlan> getProjectPlan(String userName) {
		return this.queryByProperties(new EntityCriterion().eq("userName", userName));
	}

	/**
	 * 根据Id获取
	 */
	public ProjectPlan getProjectPlan(Long id) {
		return getById(id);
	}

	/**
	 * 逻辑删除
	 */
	public int deleteProjectPlan(ProjectPlan projectPlan) {
		return update("update ls_project_plan set deleted = 1 where id = ?", projectPlan.getId());
	}

	/**
	 * 保存
	 */
	public Long saveProjectPlan(ProjectPlan projectPlan) {
		return save(projectPlan);
	}

	/**
	 * 更新
	 */
	public int updateProjectPlan(ProjectPlan projectPlan) {
		return update(projectPlan);
	}

	/**
	 * 查询列表
	 */
	public PageSupport getProjectPlan(CriteriaQuery cq) {
		return queryPage(cq);
	}

	/**
	 * 查询项目计划
	 */
	@Override
	public PageSupport<ProjectPlan> getProjectPlanByProject(ProjectPlanQueryDto projectPlanQueryDto) {
		SimpleSqlQuery query = new SimpleSqlQuery(ProjectPlan.class, projectPlanQueryDto.getCurPageNO());	
		query.setPageSize(50);
		QueryMap map = new QueryMap();
		map.put("projectId",  projectPlanQueryDto.getProjectId());
		map.put("moduleId",  projectPlanQueryDto.getModuleId());
		map.put("status", projectPlanQueryDto.getStatus());
		map.like("userName",  projectPlanQueryDto.getUserName());
		map.like("title",  projectPlanQueryDto.getTitle());
		
		//判断是否为外部排序
		if (projectPlanQueryDto.getSortResult().isSortExternal()) {
			map.put(Constants.ORDER_INDICATOR,  projectPlanQueryDto.getSortResult().parseSeq());
 		}
		
		String querySql = ConfigCode.getInstance().getCode("oa.getProjectPlan", map);
		String sqlCount = ConfigCode.getInstance().getCode("oa.getProjectPlanCount", map);
		query.setQueryString(querySql);
		query.setAllCountString(sqlCount);
		map.remove(Constants.ORDER_INDICATOR);
		query.setParam(map.toArray());
		return querySimplePage(query);
	}

	@Override
	public  List<ProjectPlan> getProjectPlan(Long projectId, Integer status){
		return queryByProperties(new LambdaEntityCriterion<>(ProjectPlan.class).eq(ProjectPlan::getProjectId,projectId).eq(ProjectPlan::getStatus, status));
	}

}
